package com.zdp.provider.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zdp.provider.controller.CourseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 类描述: 实现CourseService，在里面添加一个降级方法。
 * 接口的实现方法直接委托给该降级方法
 *
 * @author ZhhengDP
 * @since 2021/8/18
 */
@Component
public class CourseServiceFallBackImp implements CourseService{


    @Override
    public List<CourseDto> getCourses(Integer teacherId) {
        return loadCoursesFallBack(teacherId);
    }


    protected List<CourseDto> loadCoursesFallBack(Integer teacherId){
        List<CourseDto> result = new ArrayList<>();
        CourseDto course1 = new CourseDto();
        CourseDto course2 = new CourseDto();
        course1.setContent("容错课程介绍1");
        course1.setName("容错课程1");
        course1.setTeacherId(teacherId);
        course1.setCourseServicePort(9906);
        /**====================================*/
        course2.setContent("容错课程介绍2");
        course2.setName("容错课程2");
        course2.setTeacherId(teacherId);
        course2.setCourseServicePort(9906);

        result.add(course1);
        result.add(course2);
        return result;
    }


}
